package game.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import common.model.po.GBlueprintAuthor;
import common.model.request.base.PaginationRequest;
import common.model.response.base.Result;
import game.mapper.GBlueprintAuthorMapper;
import game.model.converter.GBlueprintAuthorConverter;
import game.model.request.SaveBlueprintAuthorRequest;
import game.model.request.SearchBlueprintAuthorRequest;
import game.service.GBlueprintAuthorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 服务实现类
 *
 * @author 米泽鹏
 * @since 2024-08-17 下午 06:02
 */
@Service
public class GBlueprintAuthorServiceImpl extends ServiceImpl<GBlueprintAuthorMapper, GBlueprintAuthor> implements GBlueprintAuthorService {

	@Resource
	private GBlueprintAuthorMapper mapper;

	@Override
	public Page<GBlueprintAuthor> pageBlueprintAuthor(PaginationRequest<SearchBlueprintAuthorRequest, GBlueprintAuthor> paginationRequest) {
		LambdaQueryWrapper<GBlueprintAuthor> queryWrapper = paginationRequest.buildQueryWrapper().lambda();
		queryWrapper.orderByDesc(GBlueprintAuthor::getId);
		return page(paginationRequest.buildPage(), queryWrapper);
	}

	@Override
	public Result<?> saveBlueprintAuthor(SaveBlueprintAuthorRequest request) {
		GBlueprintAuthor blueprintAuthor = GBlueprintAuthorConverter.toGBlueprintAuthor(request);
		if (request.getId() == null) {
			save(blueprintAuthor);
		} else {
			updateById(blueprintAuthor);
		}
		return Result.success();
	}

	@Override
	public Result<?> deleteBlueprintAuthor(Long id) {
		removeById(id);
		return Result.success();
	}
}
